package org.luu.medicare.controller.medicareInfoController;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.luu.medicare.common.Result;
import org.luu.medicare.entity.PageBean;
import org.luu.medicare.entity.TServiceFacility;
import org.luu.medicare.service.ServiceFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
@RestController("/facility")
public class ServiceFacilityController {
    private final ServiceFacilityService serviceFacilityService;

    @DeleteMapping("/{id}")
    public Result<String> deleteById(@PathVariable Integer id) {
        log.info("服务设施项目 deleteById: {}", id);
        return serviceFacilityService.deleteById(id);
    }

    @PostMapping
    public Result<String> save(@RequestBody TServiceFacility serviceFacility) {
        log.info("服务设施项目 save: {}", serviceFacility);
        return serviceFacilityService.save(serviceFacility);
    }

    @PutMapping
    public Result<String> update(@RequestBody TServiceFacility serviceFacility) {
        log.info("服务设施项目 update: {}", serviceFacility);
        return serviceFacilityService.update(serviceFacility);
    }

    @GetMapping("/{id}")
    public Result<TServiceFacility> findById(@PathVariable Integer id) {
        log.info("服务设施项目 findById: {}", id);
        return serviceFacilityService.findById(id);
    }

    @GetMapping
    public Result<PageBean<TServiceFacility>> page(@RequestParam(defaultValue = "1") int page,
                                                   @RequestParam(defaultValue = "10") int pageSize,
                                                   String name,
                                                   String id) {
        log.info("服务设施项目 page: {}, {}, {}, {}", page, pageSize, name, id);
        return serviceFacilityService.page(page, pageSize, name, id);
    }
}
